<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>选择应税项目</title>
		<%@ include file="/WEB-INF/jsp/include.jsp"%>

		<script type="text/javascript" src="${path}/resource/js/common/autoNumeric/autoNumeric.js"></script>
		<style type="text/css">
			 .numericInput {
				text-align:right;
			 }
		</style>		
		<script type="text/javascript">
		var numeric_options_bl_2 = {
				aSign: '%',
				pSign: 's',
				vMin: '0.00',
				vMax: '100.00'					
		};
		
		$(function(){
			setAjaxLoading();
			
			$(".numericInput").val("");
			$(".numericInput").autoNumeric('init', numeric_options_bl_2);
			
			//绑定报表页签panel的OnResize事件
			var west_panel = $("#div_container").layout("panel", "center");
			var panel_options = west_panel.panel("options");
			panel_options.onResize = resizeTree;
			
			resizeTree();
			
			initTree();
		});

		function initTree() {
			var setting = {
				callback: {
					onClick: zTreeOnClick
				},
				async: {
					enable: true,
					url: "${path}/system/taxclasscode/queryTaxableItems",
					dataType: "json",
					autoParam: ["id=pId"],
					dataFilter: ajaxDataFilter
				},				
				data: {
					simpleData: {
						enable: false,
						idKey: "id",
						pIdKey: "pId",
						rootPId: null
					},
					key: {
						name: "title"
					}					
				},
				edit: {
					enable: false					
				},
				view: {
					selectedMulti: false
				}
			};
			
			$.fn.zTree.init($("#tree"), setting, null);
       	}
		
		function zTreeOnClick(event, treeId, treeNode) {
			if (treeNode.load_sl_tbsm == undefined) {
				loadSlAndTbsm(treeNode);
			}
			
			showSlAndTbsm(treeNode);	
		}
		
		function ajaxDataFilter(treeId, parentNode, responseData) {
		    var nodes = responseData.returnObject.nodes;
		    return nodes;
		};
		
		//调整报表页签树宽高
		function resizeTree(w, h) {
			var width = $("#tree").parent().width();
			var height = $("#tree").parent().height();
			
			$("#tree").width(width);
			$("#tree").height(height);
		}
		
		function loadSlAndTbsm(treeNode) {
			var url = '${path}/system/taxclasscode/returnSingleVatTaxable';
			var param = new Object();
			param.taxableitemsId = treeNode.id;
			
			$.ajax({
				type : "POST",
				url : url,
				dataType : "json",
				data: param,
				async: false,
				success : function callback(data) {
					if (data.code != '0000') {
						//$.messager.alert('错误', data.msg, 'error',function() {});
						$.alert("default", "error", data.msg);
					} else {
						var dto = data.returnObject;
						
						var taxRateGeneral = 0.00;
						var taxRateSimple = 0.00;
						var description = "";
						
						if (dto != null) {
							if (dto.taxRateGeneral) {
                                taxRateGeneral = dto.taxRateGeneral;
							}
							if (dto.taxRateSimple) {
                                taxRateSimple = dto.taxRateSimple;
							}
							if (dto.description != null) {
                                description = dto.description;
							}
						}
						
						treeNode.taxRateGeneral = taxRateGeneral;
						treeNode.taxRateSimple = taxRateSimple;
						treeNode.description = description;
						treeNode.load_sl_tbsm = true;
					}
				},
				error : function(data, textstatus) {
					//$.messager.alert('错误', data.responseText, 'error',function(){});
					$.alert("default", "error", data.responseText);
				}
			});
		}
		
		function showSlAndTbsm(treeNode) {
			$("#taxRateGeneral").val("");
			$("#taxRateSimple").val("");
			$("#description")[0].value = "";
			
			if (treeNode.load_sl_tbsm == undefined) {
				return;
			}
			
			var taxRateGeneral = treeNode.taxRateGeneral;
			var taxRateSimple = treeNode.taxRateSimple;
			var description = treeNode.description;
			
			if (taxRateGeneral != 0.00) {
				$("#taxRateGeneral").autoNumeric("set", taxRateGeneral * 100);
			}
			if (taxRateGeneral != 0.00) {
				$("#taxRateSimple").autoNumeric("set", taxRateSimple * 100);
			}
			$("#description")[0].value = description;
		}
		
		function btnOk() {
			var treeObj = $.fn.zTree.getZTreeObj("tree");
			var nodes = treeObj.getSelectedNodes();
			if (nodes == null || nodes.length == 0) {
				//$.messager.alert('提示','请选择一个应税项目。','info',function(){});
				$.alert("pick", "info", "应税项目");
				return;
			}
			
			var node = nodes[0];
			if (node.isParent) {
				//$.messager.alert('提示','请选择末级应税项目。','info',function(){});
				$.alert("pick", "info", "末级应税项目");
				return;
			}
			
			if (node.load_sl_tbsm == undefined) {
				//$.messager.alert('提示','获取税率失败。','info',function(){});
				$.alert("get", "info", "税率");
				return;
			}
			
			var returnValue = new Object();
			returnValue.id = node.id;
			returnValue.code = node.code;
			returnValue.name = node.name;
			returnValue.taxRateGeneral = node.taxRateGeneral;
			returnValue.taxRateSimple = node.taxRateSimple;
			
			parent.window.callback_selectZzsYsxm(returnValue);
			setTimeout("closeLayer()",100);
		}
		</script>
	</head>
  <body  style="margin:0px; padding:0px;" >
  <%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" border="false">
		<div data-options="region:'center',title:'',split:false,border: false">
			<div id="div_container" class="easyui-layout" fit="true" border="false" style="padding: 5px;">
				<div data-options="region:'center',title:'',split:true,border:true">
					<ul id="tree" class="ztree" style="margin-top: 0px; padding: 0px; border-width: 0px; width:250px;overflow:auto;"></ul>
				</div>
				<div data-options="region:'south',title:'',split:false,border:true" style="height:145px;">
					<div align="center" style="padding-top: 5px; padding-bottom: 5px;">
						<table class="f_table" cellspacing="1" width="590px">
							<colgroup> 
								<col style="width:155;"></col>
								<col style="width:230;"></col>
								<col style="width:155;"></col>
								<col style="width:230;"></col>								
							</colgroup>							
							<tr>
								<td align="right" class="s_bg">
									税率（一般计税）：
								</td>
								<td align="left">
									<input type="text" id="taxRateGeneral" class="numericInput" style="width:225px;" readonly="readonly">										
								</td>															
								<td align="right" class="s_bg">
									征收率（简易计税）：
								</td>
								<td align="left">
									<input type="text" id="taxRateSimple" class="numericInput" style="width:225px;" readonly="readonly">										
								</td>															
							</tr>
							<tr>
								<td align="right" class="s_bg">
									填报说明：
								</td>					
								<td align="left" colspan="3">
									<textarea id="description" rows="" cols="" style="width: 612px; height: 80px; font-family: '微软雅黑'; font-size: 10pt;" readonly="readonly"></textarea>
								</td>
							</tr>						
						</table>
					</div>
				</div>
			</div>
		</div>
		<div data-options="region:'south',title:'',split:false,border: false" style="height:55px;">
			<div align="center" style="margin-top: 15px;">
	        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="btnOk()">确定</a>
	        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="closeLayer();">取消</a>
       		</div>
		</div>
	</div>	
</body>
</html>
